package cn.quevo.ucenter.server.dao.impl;

import org.springframework.stereotype.Repository;

import cn.quevo.beetlsql.BasicDao;
import cn.quevo.core.exception.CustomException;
import cn.quevo.ucenter.server.dao.AccessTokenDao;
import cn.quevo.ucenter.server.entity.AccessToken;
import cn.quevo.ucenter.server.entity.query.AccessTokenQuery;

/**
 * 令牌Dao接口实现
 * 
 * @author July july_sky@foxmail.com
 * @date 2018年3月26日 下午5:25:43
 * @Copyright ©2015-2035 湘豫(北京)科技有限公司. All Rights Reserved.
 * @version 1.0
 */
@Repository("accessTokenDao")
public class AccessTokenDaoImpl extends BasicDao<AccessToken, AccessTokenQuery> implements AccessTokenDao {
    
    private final static String SQL_PRE = "ucenter.server.accessToken.";
    
    @Override
    public Integer create(AccessToken accessToken) throws CustomException {
        return super.getBeetlSqlFactory().insertObject(SQL_PRE+"create", accessToken);
    }
    
    @Override
    public AccessToken getSinge(AccessTokenQuery query) throws CustomException {
        return super.getSinge(query,AccessToken.class);
    }

    @Override
    public Integer updateRefreshToken(AccessToken accessToken) {
        return super.getBeetlSqlFactory().updateObject(SQL_PRE+"updateRefreshToken", accessToken);
    }

    @Override
    public Integer createAccessTokenByRefresh(AccessToken accessToken) {
        return super.getBeetlSqlFactory().createObject(SQL_PRE+"createAccessTokenByRefresh", accessToken);
    }
    
    @Override
    public String getSqlPre() {
        return SQL_PRE;
    }

    @Override
    public Integer deleteHistory(AccessToken accessToken) throws CustomException {
        return super.getBeetlSqlFactory().updateObject(SQL_PRE+"deleteHistory", accessToken);
    }
}
